//logs.js
const app = getApp()
import {
  HomeIndex
} from 'index-modal.js';
import {
  Config
} from '../../../utils/config.js';
var Function = require("../../../utils/function.js");
var index = new HomeIndex(); //实例化 首页 对象;

Page({
  data: {
    fankui2:false,
    url:Config.Url,
    seacrvalue:'',
    prell:[],
    imgarr:[],
    hide_blok:false,
    order_hides:true,
    hostr:1,
    dples: [{ status: true, name: '接私单' }, { status: false, name: '治疗师上班离岗' }, { status: false, name: '服务沟通&态度' }, { status: false, name: '肌骨理疗效果' }
      , { status: false, name: '门店卫生&陈列' }, { status: false, name: '手法优化' }, { status: false, name: '其它' }],
    fankui:'',
    lei:'',
    jiemei:true,
    farr:[],
    count:[],
    title:"",
    type:1,
    phone:'',
    btap:'',
    norindex:99
  },
  onLoad: function () {
    this.feedback()
  },

  showBOX(){
    this.setData({
      hide_blok:true
    })
  },
  hideBOX(){
    this.setData({
      hide_blok: false
    })
  },
  selecyov(){
    this.setData({
      type:2,
      order_hides: false
    })
  },
  selecy(){
    this.setData({
      type: 1,
      order_hides: true
    })
  },
  radioChange(e){
    var index = parseInt(e.detail.value);
    var title = this.data.farr[index].title;
    this.setData({
      title
    })
  },
  bindlei(e){    //填写反馈类型
    this.setData({
      lei:e.detail.value
    })
  },
  bindonhod(e){
    this.setData({fankui:e.detail.value})
  },
  hidemodal(){
    this.setData({ jiemei:false})
  },

  selctPhone(e) {
    let that = this;
    wx.chooseImage({
      count: 5,
      success(res) {
        let prell = that.data.prell;
        let tempFilePaths = res.tempFilePaths;
        let prellarr = prell.concat(tempFilePaths);
        that.setData({
          prell: prellarr
        })
        that.Upload(tempFilePaths, function (res) {
          let imgarr = that.data.imgarr;
          let imgarr_ed = imgarr.concat(res);
          that.setData({
            imgarr: imgarr_ed
          })
        })
      }
    })
  },
  preimg(e) {
    var index = parseInt(e.currentTarget.dataset.index);
    var that = this;
    wx.previewImage({
      urls: that.data.prell,
      current: that.data.prell[index]
    })
  },

  Upload: function (fromarr, fun) {
    var len = 0;
    var tolen = fromarr.length;
    var that = this;
    var pusharr = [];
    loadImg(fromarr);
    function loadImg(fromarr_ed) {
      wx.uploadFile({
        url: 'https://yime.kailly.com/api/common/fileUp',
        header: {
          "Content-Type": "multipart/form-data",
        },
        filePath: fromarr_ed[len],
        name: 'file',
        formData: {},
        success: function (res) {
          len++;
          var datas = JSON.parse(res.data);
          if (datas.code == 200) {
            pusharr.push(datas.data)
            if (len == tolen) {
              if (fun) {
                fun(pusharr)
              }
              return;
            }
            loadImg(fromarr)
          }
        },
        fail: function (err) {
        },
        complete: function (res) { },
      })
    }
  },


  feedback(){
    let that = this;
    let data ={
      uid:wx.getStorageSync('members')['id'],
      type:that.data.type
    };
    index.feedback(data,(res)=>{
      if(res.code == 200){
        that.setData({
          farr:res.data,
          count:res.count
        })
      }
    })
  },

  fankuiover(){  //投诉
    let that = this;
    var name='';
    if (this.data.count.length==0 && that.data.btap.length==0){
      Function.layer("请选择手艺人");
      return;
    }
    if(this.data.type==1){
       name = this.data.count.name
    }else{
       name = this.data.btap.name
    }
    let data ={
      uid: wx.getStorageSync('members')['id'],
      title: that.data.title,
      type: that.data.type,
      content:that.data.fankui,
      phone:that.data.phone,
      name,
      images: that.data.imgarr.join(',')
    }

    index.fankuiover(data,(res)=>{
      if(res.code == 200){
        // wx.showToast({
        //   title: res.msg,
        //   duration:1000,
        //   icon:"none"
        // })
        that.setData({
          fankui2:true
        })
      }else{
        wx.showToast({
          title: res.msg,
          duration: 1000,
          icon: "none"
        })
      }
    })
  },

  byphone(e){
   this.setData({
     phone:e.detail.value
   })
  },

  getvals(e){
    this.setData({
      seacrvalue:e.detail.value
    })
  },

  seachok(){
    if (this.data.seacrvalue==""){
      return;
    }
    let that = this;
    let data ={
      name:that.data.seacrvalue
    }
    index.seach(data,(res)=>{
      if(res.code == 200){  
        that.setData({
          zong:res.data
        })

      }else{
        wx.showToast({
          title: res.msg,
          duration: 1000,
          icon: "none"
        })
      }
    })
  },
  selcx(e){
    var btap = this.data.btap;
    var zong = this.data.zong;
    let that=this;
    // for (let i = 0; i < that.data.btap.length;i++){
    //   if (that.data.btap[i].id == that.data.zong[parseInt(e.currentTarget.dataset.index)].id){
    //     Function.layer("已选过了");
    //     return;
    //   } 
    // }
    if (that.data.btap.length != 0){

    }
    // btap.push(zong[parseInt(e.currentTarget.dataset.index)])
    this.setData({
      norindex:parseInt(e.currentTarget.dataset.index),
      btap: zong[parseInt(e.currentTarget.dataset.index)],
      hide_blok:false
    })
  },

  hidemodal2:function(){
    let that=this;
    wx.switchTab({
      url: '/pages/my/mine/mine'
    })
  },
  romoveicl(e){
    let that=this;
    // let index = e.currentTarget.dataset.index;
    // that.data.btap.splice(index, 1);
    this.setData({
      btap: ''
    })
  }
})
